const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
var app = getApp();
Page({
  data: {
    detail: {},
    page: 1,
    endFlag: false,
    loadingFlag: false,
    flag: 0,
    navbar_bgcolor: wx.getStorageSync('navbar_bgcolor'),
    activeCategoryId: 1,
    schoolId: 0,
    model:'',
    placeList: [],  //场地信息
    classTypeList: [], //班型信息
    coachList: [],  //教练信息
    evalList:[]
  },

  onLoad: function (options) {
    var models = options.model;
    
    if('undefined' != models){
      this.setData({
        model: models
      });
    }

    this.setData({
      schoolId: options.id
    });
    //console.log(models);
    this.getSchoolDetail();
    this.getStuEval();
  },
  getStuEval:function(){
    let that = this;
    util.request(api.schoolStuEvalUrl, {
      schoolId: that.data.schoolId
    }).then(function (res) {
      //console.log(JSON.stringify(res.data));
      that.setData({
        evalList:res.data
      })
    });
  },
  getSchoolDetail: function () {
    wx.showLoading({
      title: '加载中',
    });

    setTimeout(function () {
      wx.hideLoading()
    }, 2000);

    let that = this;
    //console.log(that.data.model);
    util.request(api.SchoolDetailorModel, {
      id: that.data.schoolId,
      model:that.data.model
    }).then(function (res) {
      if (res.errno === 0) {
        console.log(res.data);
        console.log(res.data.coachList);
        that.setData({
          detail: res.data.detail,
          placeList: res.data.placeList,
          classTypeList: res.data.classTypeList,
          coachList: res.data.coachList
        });
      }

      wx.hideLoading();
    });
  },


  tabClick: function (e) {
    this.setData({
      //activeIndex: e.currentTarget.id
      activeCategoryId: e.currentTarget.id
    });
  },

  tobm: function (e) {
    /*var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name
    wx.navigateTo({
      url: '/pages/signup/add?jiaxiaoId=' + id + "&jiaxiaoName=" + name
    })*/
    var hasLogin = wx.getStorageSync("app.globalData.hasLogin");
    if (!hasLogin) {
      wx.navigateTo({
        url: '/pages/auth/login/login',
      })
    }else{
      wx.navigateTo({
        url: '/pages/signupV3/selectCarModel?schoolId='+this.data.schoolId+'&schoolName='+this.data.detail.name,
      })
    }
  },

  onShareAppMessage: function (res) {
  },
  onPullDownRefresh: function () {
  }
  ,
  //地图跳转
  fnMap: function (e) {
    var location = e.currentTarget.dataset.location;
  },
  toNav: function (e) {
    var latitude=this.data.detail.latitude;
    var longitude=this.data.detail.longitude;
    var name=this.data.detail.name;
    var address=this.data.detail.address;
    wx.openLocation({//?使用微信内置地图查看位置。
      latitude: Number(latitude),//要去地点的纬度
      longitude: Number(longitude),///要去地点的经度-地址
      name: name,//
      address: address
    })
  }
})